package com.cyzy.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cyzy.dto.Result;
import com.cyzy.pojo.ClassSchedule;
import com.cyzy.service.ClassScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/schedule")
public class ClassScheduleController {

    @Autowired
    private ClassScheduleService classScheduleService;

    @GetMapping("/getSchedule")
    public Result getSchedule(ClassSchedule classSchedule){
        return Result.ok().data("schedule", classScheduleService.getSchedule(classSchedule));
    }

    @PutMapping("/scheduleManage")
    public Result scheduleManage(@RequestBody List<ClassSchedule> classSchedule){
        System.out.println(classSchedule);
        ClassSchedule classSchedule1 = classSchedule.get(0);
        String classId = classSchedule1.getClassId();
        LambdaQueryWrapper<ClassSchedule> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ClassSchedule::getClassId, classId);
        classScheduleService.remove(queryWrapper);
        classScheduleService.saveBatch(classSchedule);
        return Result.ok().message("修改成功");
    }

}
